$(document).ready(function()
{
	$("#checkAll").click(function()				
	{
		var checked_status = this.checked;
		$("input[id=cid]").each(function()
		{
			this.checked = checked_status;
		});
	});
	
	
	/**
	 * Submit with an acttion
	 */
	systemForm.submitAct = function(act) {
		if ($.validator && (act == 'save' || act == 'apply')) {
			if (!$('#systemForm').valid()) {
				return;
			}
		}
		systemForm.setAct(act);
		systemForm.submit();
	}

	/**
	 * Submit with an task
	 */
	systemForm.submitTask = function(task) {
		if ($.validator && (task == 'save' || task == 'apply')) {
			if (!$('#systemForm').valid()) {
				return;
			}
		}
		systemForm.setTask(task);
		systemForm.submit();
	}

	/**
	 * Submit with an task
	 */
	systemForm.submitOption = function(option) {
		if ($.validator && (option == 'save' || option == 'apply')) {
			if (!$('#systemForm').valid()) {
				return;
			}
		}
		systemForm.setOption(option);
		systemForm.submit();
	}

});

function shouldDelete(ele){
	if(!($('input[@id=cid]:checked').size() > 0)){
   		alert('Please select at least one item to delete!');
	}else{
		var answer = confirm("Are you sure you want to delete the selected item(s)?");
	    if (answer){
	    	return true;
	    }
	}
	return false;
}

function shouldEdit(ele){
	if($('input[@id=cid]:checked').size() != 1){
   		alert('Please select one item to edit!');
	}else{
    	return true;
	}
	return false;
}

function editActItem(cid) {
	systemForm.setAct('edit');
	systemForm.setValue("cid[]", cid);
	systemForm.submit();
}

function doActItem(actName, cid) {
	systemForm.setAct(actName);
	systemForm.setValue("cid[]", cid);
	systemForm.submit();
}

function editTaskItem(cid) {
	systemForm.setTask('edit');
	systemForm.setValue("cid[]", cid);
	systemForm.submit();
}

function doTaskItem(taskName, cid) {
	systemForm.setTask(taskName);
	systemForm.setValue("cid[]", cid);
	systemForm.submit();
}

function editOptionItem(cid) {
	systemForm.setOption('edit');
	systemForm.setValue("cid[]", cid);
	systemForm.submit();
}

function doOptionItem(optName, cid) {
	systemForm.setOption(optName);
	systemForm.setValue("cid[]", cid);
	systemForm.submit();
}